package work.jame.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import work.jame.blog.pojo.UserMessage;
import work.jame.blog.mapper.UserMessageMapper;
import work.jame.blog.service.UserMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Jame
 * @since 2023-05-14
 */
@Service
public class UserMessageServiceImpl extends ServiceImpl<UserMessageMapper, UserMessage> implements UserMessageService {

    @Override
    public Long queryNoReadMessageCount(Long receiveUserId) {
        QueryWrapper<UserMessage> wrapper = new QueryWrapper<>();
        wrapper.eq("receive_user_id", receiveUserId)
                .eq("receive_user_read", false);
        return this.count(wrapper);
    }

    @Override
    public boolean sendMessageToUser(Long sendUserId, Long receiveUserId, String content) {
        UserMessage message = new UserMessage();
        message.setSendUserId(sendUserId);
        message.setReceiveUserId(receiveUserId);
        message.setContent(content);
        message.setType(1);
        return this.save(message);
    }

    @Override
    public boolean sendCallMessageToUser(Long sendUserId, Long receiveUserId, String content, String contentUrl) {
        UserMessage message = new UserMessage();
        message.setSendUserId(sendUserId);
        message.setReceiveUserId(receiveUserId);
        message.setContent(content);
        message.setType(2);
        message.setContentUrl(contentUrl);
        return this.save(message);
    }


}
